# -*-coding:utf-8 -*-
"""
绘制K线图
"""
from functools import reduce
from os import close
from typing import List, Sequence, Union
from numpy.core.numeric import NaN
from numpy.lib.function_base import append
from pyecharts.commons.utils import JsCode
from pyecharts.charts import Bar, Kline, Line, Grid
from pyecharts import options as opts  # 配置项
from pyecharts.globals import ThemeType
from pyecharts.options.charts_options import CandleStickItem
from pyecharts.options.global_options import InitOpts
from pyecharts.types import SplitLine  # 主题
import pandas as pd
import pandas_ta as ta


class ChartsView(object):

    def __init__(self, outdir="./outhtml/", index0data=None, index0bdata=None, index0adata=None):
        self.outdir = outdir
        self.index0data = index0data
        self.index0bdata = index0bdata
        self.index0adata = index0adata

        self.run()

    def run(self):
        self.__index0_view()  # 0号指标渲染
        self.__index0amv_view()  # 0AMV指数渲染
        self.__index0a_view()  # 0A指数渲染
        self.__index0b_view()  # 0B指数渲染

        # self._test()  # 测试

    def __index0_view(self):
        """
        0号指标
        """
        outfile = self.outdir+"index0.html"
        data_origin = self.__index0_data()
        data = self._k_split_data(data_origin)
        # print(data['vols']) #成交量 亿股

        # print(data)
        title_opt = {
            "title": "0号指标",
            "subtitle": "日期:{0}-{1}".format(data['times'][0], data['times'][-1]),
            "vol_title": "成交量（亿股）"
        }
        axis_opt = {
            "yname": "0号指标价格（亿元）",
            "vol_name": "成交量（亿股）"
        }
        self._draw_chart_kline(data=data, outfile=outfile,
                               title_opt=title_opt, axis_opt=axis_opt)

    def __index0b_view(self):
        """
        0B号指标
        """
        outfile = self.outdir+"index0b.html"
        data_origin = self.__index0b_data()
        data = self._k_split_data(data_origin)
      
        title_opt = {
            "title": "0B指数指标",
            "subtitle": "日期:{0}-{1}".format(data['times'][0], data['times'][-1])
        }
        axis_opt = {
            "yname": "0B指数流通盘（亿股）"
        }
        self._draw_chart_line(data=data, outfile=outfile,
                              title_opt=title_opt, axis_opt=axis_opt)

    def __index0a_view(self):
        """
        0A号指标
        """
        outfile = self.outdir+"index0a.html"
        data_origin = self.__index0a_data()
        data = self._k_split_data(data_origin)
        title_opt = {
            "title": "0A指数指标",
            "subtitle": "日期:{0}-{1}".format(data['times'][0], data['times'][-1]),
            "vol_title": "成交量（亿股）"
        }
        axis_opt = {
            "yname": "0A指数价格（元）",
            "vol_name": "成交量（亿股）"
        }
        self._draw_chart_kline(data=data, outfile=outfile,
                               title_opt=title_opt, axis_opt=axis_opt)

    def __index0amv_view(self):
        """
        0AMV指数-指标
        """
        outfile = self.outdir+"index0amv.html"
        data_origin = self.__index0amv_data()
        data = self._k_split_data(data_origin, type='0AMV')
        title_opt = {
            "title": "0AMV指数指标",
            "subtitle": "日期:{0}-{1}".format(data['times'][0], data['times'][-1]),

        }
        axis_opt = {
            "yname": "0AMV指数",
        }
        # print(len(data['times']))
        self._draw_0amv_kline(data=data, outfile=outfile,
                              title_opt=title_opt, axis_opt=axis_opt)

    def __index0_data(self) -> List:
        """
        0号指标数据
        DF格式数据处理为dict数据
        数字格式转换为python 原生 int
        """
        # 转化为亿元
        self.index0data['open_0'] = self.index0data['open_0']/100000000
        self.index0data['high_0'] = self.index0data['high_0']/100000000
        self.index0data['low_0'] = self.index0data['low_0']/100000000
        self.index0data['close_0'] = self.index0data['close_0']/100000000
        self.index0data['vol_0'] = self.index0data['vol_0']/100000000
        self.index0data['amount_0'] = self.index0data['amount_0']/100000000
        self.index0data['tq_0'] = self.index0data['tq_0']/100000000
        # 调整列顺序
        self.index0data = self.index0data[[
            'date', 'open_0', 'close_0', 'low_0', 'high_0', 'vol_0', 'amount_0', 'tq_0']]
        # 添加其他指标
        # macd 指标 MACD_12_26_9,MACDh_12_26_9,MACDs_12_26_9,
        self.index0data.ta.macd(close="close_0", append=True,)
        # dmi 指标： ADX_14,DMP_14,DMN_14,ADXR_14_6
        self.index0data = self._get_dmi_indicator_data(
            pd_data=self.index0data, high='high_0', low='low_0', close='close_0')

        # CYE 指标 CYEL CYES
        self.index0data = self._get_cye_indicator_data(
            pd_data=self.index0data, close='close_0')

        # CYC 指标 CYC5 CYC13，CYC34 CYC_inf
        self.index0data = self._get_cyc_indicator_data(
            pd_data=self.index0data, length=5)
        self.index0data = self._get_cyc_indicator_data(
            pd_data=self.index0data, length=13)
        self.index0data = self._get_cyc_indicator_data(
            pd_data=self.index0data, length=34)
        self.index0data = self.__cyc_inf(
            pd_data=self.index0data)

        # 0amv 指标 5个 0amv,0amv_c5,0amv_c13,0amv_c34,0amv_cinf
        self.index0data = self._get_oamv_indicator_data(
            pd_data=self.index0data)

        self.index0data.drop('tq_0', axis=1, inplace=True)
        # print(self.index0data.head(50))
        # 替换NAN数据
        self.index0data.fillna(0, inplace=True)
        # print(self.index0data.head(50))
        return self.index0data.values.tolist()

    def __index0b_data(self) -> List:
        """
        0B指数
        DF格式数据处理为list数据
        数字格式转换为python 原生int
        """
        # 转化为亿股
        self.index0bdata['tq_0'] = self.index0bdata['tq_0']/100000000
        return self.index0bdata.values.tolist()

    def __index0a_data(self) -> List:
        """
        0a指标数据
        DF格式数据处理为list数据
        数字格式转化为python 原生 int
        """
        # 调整列顺序
        # self.index0adata.drop('tq_0', axis=1, inplace=True)
        self.index0adata['vol_0'] = self.index0adata['vol_0']/100000000
        self.index0adata['amount_0'] = self.index0adata['amount_0']/100000000
        self.index0adata['tq_0'] = self.index0adata['tq_0']/100000000
        self.index0adata = self.index0adata[[
            'date', 'open_0A', 'close_0A', 'low_0A', 'high_0A', 'vol_0', 'amount_0', 'tq_0']]
        # macd 指标 MACD_12_26_9,MACDh_12_26_9,MACDs_12_26_9,  index[7,8,9]
        self.index0adata.ta.macd(close="close_0A", append=True,)
        # dmi 指标： ADX_14,DMP_14,DMN_14,ADXR_14_6   index[10,11,12,13]
        self.index0adata = self._get_dmi_indicator_data(
            pd_data=self.index0adata, high='high_0', low='low_0', close='close_0')
        # CYE 指标 :CYEL CYES  index[14,15]
        self.index0adata = self._get_cye_indicator_data(
            pd_data=self.index0adata, close='close_0A')
        # CYC 指标 CYC5 CYC13，CYC34 CYC_inf index[16,17,18,19]
        self.index0adata = self._get_cyc_indicator_data(
            pd_data=self.index0adata, length=5)
        self.index0adata = self._get_cyc_indicator_data(
            pd_data=self.index0adata, length=13)
        self.index0adata = self._get_cyc_indicator_data(
            pd_data=self.index0adata, length=34)
        self.index0adata = self.__cyc_inf(pd_data=self.index0adata)

        # 0amv 指标 5个 0amv,0amv_c5,0amv_c13,0amv_c34,0amv_cinf index[20,21,22,23,24]
        self.index0adata = self._get_oamv_indicator_data(
            pd_data=self.index0adata)

        self.index0adata.drop('tq_0', axis=1, inplace=True)
        # 替换NaN数据
        self.index0adata.fillna(0, inplace=True)

        return self.index0adata.values.tolist()

    def __index0amv_data(self) -> List:
        """
        0AMV 数据处理
        """
        # 调整列顺序
        # self.index0adata.drop('tq_0', axis=1, inplace=True)
        oamv_data = self.index0adata.copy(deep=True)

        oamv_data['vol_0'] = oamv_data['vol_0']/100000000
        oamv_data['amount_0'] = oamv_data['amount_0']/100000000
        oamv_data['tq_0'] = oamv_data['tq_0']/100000000
        oamv_data = oamv_data[[
            'date', 'open_0A', 'close_0A', 'low_0A', 'high_0A', 'vol_0', 'amount_0', 'tq_0']]

        # 获取0AMV k线以及Ma数据，共计6个
        oamv_data = self._get_0mav_intime__indicator_data(pd_data=oamv_data)
        # print(oamv_data.columns)
        # 替换NaN数据
        oamv_data.fillna(0, inplace=True)
        pd_ = oamv_data[['date', '0amvo', '0amvc', '0amvl',
                         '0amvh', '0amvcma5_SMA_5', '0amvcma10_SMA_10']]
        # 返回CYEL 和CYES 两个指标 index=[7,8]
        pd_ = self._get_cye_indicator_data(pd_data=pd_, close='0amvc')
        # print(pd_.head(50))
        pd_.fillna(0,inplace=True)
        return pd_.values.tolist()

    def _k_split_data(self, origin_data, type=None) -> dict:
        """
        处理数据为字典
        """
        if type == '0AMV':
            datas = []  # 数据源
            times = []  # 时间线
            amv_ma5 = []  #
            amv_ma10 = []  #
            cyels = []
            cyess = []
            for i in range(len(origin_data)):
                datas.append(origin_data[i][1:])
                times.append(origin_data[i][0:1][0])
                amv_ma5.append(origin_data[i][5])
                amv_ma10.append(origin_data[i][6])

                cyels.append(origin_data[i][7])
                cyess.append(origin_data[i][8])
            return {
                "datas": datas,
                "times": times,
                "0amv_ma5": amv_ma5,
                "0amv_ma10": amv_ma10,
                "cyels": cyels,
                "cyess": cyess,
            }

        datas = []  # 数据源
        times = []  # 时间线
        closes = []  # 收盘价
        vols = []  # 成交量

        # macd 3个指标
        macds = []  # macd
        difs = []  # difs
        deas = []  # deas

        # DMI 4个指标
        adxs = []
        dmps = []
        dmns = []
        adxrs = []

        # CYE 2个指标
        cyels = []
        cyess = []

        # CYC 4个指标 -暂未实现 CYC远期
        cyc_5 = []
        cyc_13 = []
        cyc_34 = []
        cyc_inf = []

        # 0amv 5个指标
        amv = []
        amv_c5 = []
        amv_c13 = []
        amv_c34 = []
        amv_cinf = []

        for i in range(len(origin_data)):
            datas.append(origin_data[i][1:])
            times.append(origin_data[i][0:1][0])

            if len(origin_data[i]) >= 6:
                closes.append(origin_data[i][2])
                vols.append(int(origin_data[i][6]))
                macds.append(origin_data[i][7])
                difs.append(origin_data[i][8])
                deas.append(origin_data[i][9])

                adxs.append(origin_data[i][10])
                dmps.append(origin_data[i][11])
                dmns.append(origin_data[i][12])
                adxrs.append(origin_data[i][13])

                cyels.append(origin_data[i][14])
                cyess.append(origin_data[i][15])

                cyc_5.append(origin_data[i][16])
                cyc_13.append(origin_data[i][17])
                cyc_34.append(origin_data[i][18])
                cyc_inf.append(origin_data[i][19])

                amv.append(origin_data[i][20])
                amv_c5.append(origin_data[i][21])
                amv_c13.append(origin_data[i][22])
                amv_c34.append(origin_data[i][23])
                amv_cinf.append(origin_data[i][24])

        return {
            "datas": datas,
            "times": times,
            "closes": closes,
            "vols": vols,
            "macds": macds,
            "difs": difs,
            "deas": deas,

            "adxs": adxs,
            "dmps": dmps,
            "dmns": dmns,
            "adxrs": adxrs,

            "cyels": cyels,
            "cyess": cyess,

            "cyc_5": cyc_5,
            "cyc_13": cyc_13,
            "cyc_34": cyc_34,
            "cyc_inf": cyc_inf,

            "0amv": amv,
            "0amv_c5": amv_c5,
            "0amv_c13": amv_c13,
            "0amv_c34": amv_c34,
            "0amv_cinf": amv_cinf,

        }

    def _draw_0amv_kline(self, data=None, outfile=None, title_opt=None, axis_opt=None):
        """
        画0AMV曲线
        """

        kline = (Kline()
                 .add_xaxis(data['times'])
                 .add_yaxis(
            series_name=title_opt['title'],  # 系列名称
            y_axis=data['datas'],  # open,close,low,high  顺序
            itemstyle_opts=opts.ItemStyleOpts(
                color="#ec0000",
                color0="#00da3c",
                border_color="#8A0000",
                border_color0="#008F28",
            ),
        )

            .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitline_opts=opts.SplitLineOpts(is_show=False,
                                                  linestyle_opts=opts.LineStyleOpts(opacity=1),)
                # name="日期",
                # name_location="center",
                # name_gap=30,
                # name_textstyle_opts=opts.TextStyleOpts(
                #     color="#ec0000",
                #     font_size=16,
                #     font_weight="bold"
                # )
            ),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)
                ),
                name=axis_opt['yname'],
                name_location="middle",
                name_gap=100,
                name_textstyle_opts=opts.TextStyleOpts(
                    color="#ec0000",
                    font_size=16,
                    font_weight="bold"
                )
            ),
            datazoom_opts=[
                opts.DataZoomOpts(is_show=False, type_='inside',
                                  xaxis_index=[0, 0],
                                  range_end=100),
                opts.DataZoomOpts(is_show=True,
                                  xaxis_index=[0, 1], pos_top="97%", range_end=100),
            ],
            title_opts=opts.TitleOpts(
                title=title_opt['title'],
                subtitle=title_opt['subtitle'],
                title_textstyle_opts=opts.TextStyleOpts(
                    font_size=25,
                    color="#ec0000"

                ),
                subtitle_textstyle_opts=opts.TextStyleOpts(
                    font_size=14
                ),
            ),
            toolbox_opts=opts.ToolboxOpts(
                is_show=True,
                # feature=opts.ToolBoxFeatureSaveAsImageOpts(
                #     type_='png',
                #     pixel_ratio=2)
            ),  # 工具箱

            tooltip_opts=opts.TooltipOpts(
                is_show=True, trigger="axis", axis_pointer_type="cross"),  # 提示框
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%", pos_top="10%")


        )
        )
        kline_close_ma = (Line()
                          .add_xaxis(xaxis_data=data['times'])
                          .add_yaxis(
            series_name="0AMV-MA5",
            y_axis=data['0amv_ma5'],
            symbol="roundRect",
            symbol_size=6,
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(
                opacity=0.8, width=2),
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name="0AMV-MA10",
            y_axis=data['0amv_ma10'],
            symbol="triangle",
            symbol_size=6,
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(
                opacity=0.8, width=2),
            label_opts=opts.LabelOpts(is_show=False),
        )
            .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=0,
                axislabel_opts=opts.LabelOpts(
                    is_show=False)
            ),
            yaxis_opts=opts.AxisOpts(
                grid_index=0,
                split_number=3,
                axisline_opts=opts.AxisLineOpts(
                    is_on_zero=False),
                axistick_opts=opts.AxisTickOpts(
                    is_show=False),
                splitline_opts=opts.SplitLineOpts(
                    is_show=False),
                axislabel_opts=opts.LabelOpts(
                    is_show=False)
            ),
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%"),
        )
        )
        overlap_kline_ma = kline.overlap(kline_close_ma)


        cye_line = (Line()
                    .add_xaxis(xaxis_data=data['times'])
                    .add_yaxis(
            series_name='CYEL',
            y_axis=data['cyels'],
            symbol="rect",
            symbol_size=6,
            xaxis_index=4,
            yaxis_index=4,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name='CYES',
            y_axis=data['cyess'],
            symbol="triangle",
            symbol_size=6,
            xaxis_index=4,
            yaxis_index=4,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=4,
                axislabel_opts=opts.LabelOpts(is_show=False)
            ),
            yaxis_opts=opts.AxisOpts(

                name="CYE-指标",
                name_location="middle",
                name_gap=50,
                name_textstyle_opts=opts.TextStyleOpts(
                    color="#ec0000",
                    font_size=16,
                    font_weight="bold"
                ),
            ),
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%", pos_top="62%")
        )

        )
        grid_chart = Grid(init_opts=opts.InitOpts(
            width="1900px", height="1200px", page_title=title_opt['title'],
            theme=ThemeType.LIGHT,))

        # 传参数至html中
        # grid_chart.add_js_funcs("var barData={}".format(data['datas']))
        # grid_chart.add_js_funcs("var amvbarData={}".format(data['0amv']))
        # k线图 index=0
        grid_chart.add(
            overlap_kline_ma,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                height="60%"),)
        # CYE : CYEL CYES
        grid_chart.add(
            cye_line,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                pos_top="70%",
                height="25%",
            )
        )
        grid_chart.render(outfile)

    def _draw_chart_kline(self, data=None, outfile=None, title_opt=None, axis_opt=None):
        """
        画图 K线 蜡烛图
        """
        kline = (Kline()
                 .add_xaxis(data['times'])
                 .add_yaxis(
            series_name=title_opt['title'],  # 系列名称
            y_axis=data['datas'],  # open,close,low,high  顺序
            itemstyle_opts=opts.ItemStyleOpts(
                color="#ec0000",
                color0="#00da3c",
                border_color="#8A0000",
                border_color0="#008F28",
            ),
        )

            .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitline_opts=opts.SplitLineOpts(is_show=False,
                                                  linestyle_opts=opts.LineStyleOpts(opacity=1),)
                # name="日期",
                # name_location="center",
                # name_gap=30,
                # name_textstyle_opts=opts.TextStyleOpts(
                #     color="#ec0000",
                #     font_size=16,
                #     font_weight="bold"
                # )
            ),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)
                ),
                name=axis_opt['yname'],
                name_location="middle",
                name_gap=100,
                name_textstyle_opts=opts.TextStyleOpts(
                    color="#ec0000",
                    font_size=16,
                    font_weight="bold"
                )
            ),
            datazoom_opts=[
                opts.DataZoomOpts(is_show=False, type_='inside',
                                  xaxis_index=[0, 0],
                                  range_end=100),
                opts.DataZoomOpts(is_show=True,
                                  xaxis_index=[0, 1], pos_top="97%", range_end=100),
                opts.DataZoomOpts(is_show=False, xaxis_index=[
                                  0, 2], range_end=100),
                opts.DataZoomOpts(is_show=False, xaxis_index=[
                    0, 3], range_end=100),
                opts.DataZoomOpts(is_show=False, xaxis_index=[
                    0, 4], range_end=100),
                opts.DataZoomOpts(is_show=False, xaxis_index=[
                    0, 5], range_end=100),
                opts.DataZoomOpts(is_show=False, xaxis_index=[
                    0, 6], range_end=100),

            ],
            title_opts=opts.TitleOpts(
                title=title_opt['title'],
                subtitle=title_opt['subtitle'],
                title_textstyle_opts=opts.TextStyleOpts(
                    font_size=25,
                    color="#ec0000"

                ),
                subtitle_textstyle_opts=opts.TextStyleOpts(
                    font_size=14
                ),
            ),
            toolbox_opts=opts.ToolboxOpts(
                is_show=True,
                # feature=opts.ToolBoxFeatureSaveAsImageOpts(
                #     type_='png',
                #     pixel_ratio=2)
            ),  # 工具箱

            tooltip_opts=opts.TooltipOpts(
                is_show=True, trigger="axis", axis_pointer_type="cross"),  # 提示框
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%", pos_top="10%")


        )
        )
        kline_close_ma = (Line()
                          .add_xaxis(xaxis_data=data['times'])
                          .add_yaxis(
            series_name="MA5",
            y_axis=self._calculate_ma(
                day_count=5, times=data['times'], data=data['closes']),
            symbol="roundRect",
            symbol_size=6,
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(
                opacity=0.8, width=2),
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name="MA10",
            y_axis=self._calculate_ma(
                day_count=10, times=data['times'], data=data['closes']),
            symbol="triangle",
            symbol_size=6,
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(
                opacity=0.8, width=2),
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name="MA20",
            y_axis=self._calculate_ma(
                day_count=20, times=data['times'], data=data['closes']),
            symbol="diamond",
            symbol_size=6,
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(
                opacity=0.8, width=2),
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name="MA60",
            y_axis=self._calculate_ma(
                day_count=60, times=data['times'], data=data['closes']),
            symbol="pin",
            symbol_size=6,
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(
                opacity=0.8, width=2),
            label_opts=opts.LabelOpts(is_show=False),
        )
            .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=0,
                axislabel_opts=opts.LabelOpts(
                    is_show=False)
            ),
            yaxis_opts=opts.AxisOpts(
                grid_index=0,
                split_number=3,
                axisline_opts=opts.AxisLineOpts(
                    is_on_zero=False),
                axistick_opts=opts.AxisTickOpts(
                    is_show=False),
                splitline_opts=opts.SplitLineOpts(
                    is_show=False),
                axislabel_opts=opts.LabelOpts(
                    is_show=False)
            ),
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%", pos_top="12%"),
        )
        )
        overlap_kline_ma = kline.overlap(kline_close_ma)
        vols_bar = (
            Bar()
            .add_xaxis(
                xaxis_data=data['times'],
            )
            .add_yaxis(
                series_name=title_opt['vol_title'],
                y_axis=data['vols'],
                xaxis_index=1,
                yaxis_index=1,
                label_opts=opts.LabelOpts(is_show=False),
                itemstyle_opts=opts.ItemStyleOpts(
                    color=JsCode(
                        """
                        function(params){
                            var colorList;
                            if (barData[params.dataIndex][1] > barData[params.dataIndex][0]) {
                                colorList = '#ef232a';
                            } else {
                                colorList = '#14b143';
                            }
                            return colorList;
                        }
                        """
                    )
                ),
            )
            .set_global_opts(
                xaxis_opts=opts.AxisOpts(
                    type_="category",
                    grid_index=1,
                    axislabel_opts=opts.LabelOpts(
                        is_show=True
                    ),
                ),
                yaxis_opts=opts.AxisOpts(
                    name="成交量-指标",
                    name_location="middle",
                    name_gap=50,
                    name_textstyle_opts=opts.TextStyleOpts(
                        color="#ec0000",
                        font_size=16,
                        font_weight="bold"
                    )
                ),

                legend_opts=opts.LegendOpts(
                    is_show=True,
                    orient="vertical", pos_left="1%", pos_top="40%"

                ),
            )
        )
        vol_ma_line = (Line()
                       .add_xaxis(xaxis_data=data['times'])
                       .add_yaxis(
            series_name="VOL-MA5",
            y_axis=self._calculate_ma(
                day_count=5, times=data['times'], data=data['vols']),
            symbol="diamond",
            symbol_size=6,
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(
                opacity=0.8, width=2, color="#fff000"),
            label_opts=opts.LabelOpts(is_show=False)
        )
            .add_yaxis(
                series_name="VOL_MA10",
                y_axis=self._calculate_ma(
                    day_count=10, times=data['times'], data=data['vols']),
                symbol_size=6,
                is_smooth=True,
                linestyle_opts=opts.LineStyleOpts(opacity=0.5),
                label_opts=opts.LabelOpts(is_show=False)
        )
            .set_global_opts(
                xaxis_opts=opts.AxisOpts(
                    type_="category", grid_index=1, axislabel_opts=opts.LabelOpts(is_show=False)),
                yaxis_opts=opts.AxisOpts(
                    grid_index=1,
                    split_number=3,
                    axisline_opts=opts.AxisLineOpts(is_on_zero=False),
                    axistick_opts=opts.AxisTickOpts(is_show=False),
                    splitline_opts=opts.SplitLineOpts(is_show=False),
                    axislabel_opts=opts.LabelOpts(is_show=True)
                ),
                legend_opts=opts.LegendOpts(
                    is_show=True, orient="vertical", pos_left="1%", ),
        ))

        overlap_vols_bar = vols_bar.overlap(vol_ma_line)

        macd_bar = (Bar()
                    .add_xaxis(xaxis_data=data['times'])
                    .add_yaxis(
            series_name="MACD",
            y_axis=data['macds'],

            xaxis_index=2,
            yaxis_index=2,
            label_opts=opts.LabelOpts(is_show=False,), itemstyle_opts=opts.ItemStyleOpts(
                color=JsCode(
                    """
                                function(params) {
                                    var colorList;
                                    if (params.data >= 0) {
                                    colorList = '#ef232a';
                                    } else {
                                    colorList = '#14b143';
                                    }
                                    return colorList;
                                }
                        
                            """
                )),
        )
            .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=2,
                axislabel_opts=opts.LabelOpts(is_show=False)
            ),
            yaxis_opts=opts.AxisOpts(
                grid_index=2,
                split_number=4,
                axisline_opts=opts.AxisLineOpts(is_on_zero=False),
                axistick_opts=opts.AxisTickOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
                axislabel_opts=opts.LabelOpts(is_show=True,),

                name="MACD-指标",
                name_location="middle",
                name_gap=50,
                name_textstyle_opts=opts.TextStyleOpts(
                    color="#ec0000",
                    font_size=16,
                    font_weight="bold"
                )
            ),
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%", pos_top="55%"),
        )
        )
        macd_line = (Line()
                     .add_xaxis(xaxis_data=data['times'])
                     .add_yaxis(
            series_name="DIF",
            y_axis=data['difs'],
            xaxis_index=2,
            yaxis_index=2,
            symbol="rect",
            symbol_size=6,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name='DEA',
            y_axis=data['deas'],
            symbol="roundRect",
            symbol_size=6,
            xaxis_index=2,
            yaxis_index=2,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .set_global_opts(
            legend_opts=opts.LegendOpts(is_show=True, orient="vertical", pos_left="1%", ))
        )
        overlap_macd_bar_line = macd_bar.overlap(macd_line)

        dmi_line = (Line()
                    .add_xaxis(xaxis_data=data['times'])
                    .add_yaxis(
                        series_name="ADX_14",
                        y_axis=data['adxs'],
                        symbol="roundRect",
                        symbol_size=10,
                        xaxis_index=3,
                        yaxis_index=3,
                        label_opts=opts.LabelOpts(is_show=False),

        )
            .add_yaxis(
            series_name="DMP_14",
            y_axis=data['dmps'],
            symbol="triangle",
            symbol_size=6,
            xaxis_index=3,
            yaxis_index=3,
            label_opts=opts.LabelOpts(is_show=False),

        )
            .add_yaxis(
            series_name="DMN_14",
            y_axis=data['dmns'],
            symbol="diamond",
            symbol_size=6,
            xaxis_index=3,
            yaxis_index=3,
            label_opts=opts.LabelOpts(is_show=False),

        )
            .add_yaxis(
            series_name="ADXRS_14_6",
            y_axis=data['adxrs'],
            symbol="pin",
            xaxis_index=3,
            yaxis_index=3,
            label_opts=opts.LabelOpts(is_show=False),

        )
            .set_global_opts(
                yaxis_opts=opts.AxisOpts(

                    name="DMI-指标",
                    name_location="middle",
                    name_gap=50,
                    name_textstyle_opts=opts.TextStyleOpts(
                        color="#ec0000",
                        font_size=16,
                        font_weight="bold"
                    ),
                ),
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%", pos_top="66%")
        )
        )

        cye_line = (Line()
                    .add_xaxis(xaxis_data=data['times'])
                    .add_yaxis(
            series_name='CYEL',
            y_axis=data['cyels'],
            symbol="rect",
            symbol_size=6,
            xaxis_index=4,
            yaxis_index=4,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name='CYES',
            y_axis=data['cyess'],
            symbol="triangle",
            symbol_size=6,
            xaxis_index=4,
            yaxis_index=4,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=4,
                axislabel_opts=opts.LabelOpts(is_show=False)
            ),
            yaxis_opts=opts.AxisOpts(

                name="CYE-指标",
                name_location="middle",
                name_gap=50,
                name_textstyle_opts=opts.TextStyleOpts(
                    color="#ec0000",
                    font_size=16,
                    font_weight="bold"
                ),
            ),
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%", pos_top="72%")
        )

        )

        cyc_line = (Line()
                    .add_xaxis(xaxis_data=data['times'])
                    .add_yaxis(
            series_name='CYC5',
            y_axis=data['cyc_5'],
            symbol="rect",
            symbol_size=6,
            xaxis_index=5,
            yaxis_index=5,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name='CYC13',
            y_axis=data['cyc_13'],
            symbol="triangle",
            symbol_size=6,
            xaxis_index=5,
            yaxis_index=5,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name='CYC34',
            y_axis=data['cyc_34'],
            symbol="diamond",
            symbol_size=6,
            xaxis_index=5,
            yaxis_index=5,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .add_yaxis(
            series_name='CYC_inf',
            y_axis=data['cyc_inf'],
            symbol="pin",
            symbol_size=6,
            xaxis_index=5,
            yaxis_index=5,
            label_opts=opts.LabelOpts(is_show=False),
        )
            .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=5,
                axislabel_opts=opts.LabelOpts(is_show=False)
            ),
            yaxis_opts=opts.AxisOpts(

                name="CYC-指标",
                name_location="middle",
                name_gap=50,
                name_textstyle_opts=opts.TextStyleOpts(
                    color="#ec0000",
                    font_size=16,
                    font_weight="bold"
                ),
            ),
            legend_opts=opts.LegendOpts(
                is_show=True, orient="vertical", pos_left="1%", pos_top="78%")
        )

        )

        # 0mav 活筹指数
        amvs_bar = (
            Bar()
            .add_xaxis(
                xaxis_data=data['times'],
            )
            .add_yaxis(
                series_name="0AMV-活筹指数",
                y_axis=data['0amv'],
                xaxis_index=6,
                yaxis_index=6,
                label_opts=opts.LabelOpts(is_show=False),
                itemstyle_opts=opts.ItemStyleOpts(
                    color=JsCode(
                        """
                        function(params){
                            var colorList;
                           
                            if (params.dataIndex!=0 && amvbarData[params.dataIndex]> amvbarData[params.dataIndex-1]) {
                                colorList = '#ef232a';
                            } else {
                                colorList = '#14b143';
                            }
                            return colorList;
                        }
                        """
                    )
                ),
            )
            .set_global_opts(
                xaxis_opts=opts.AxisOpts(
                    type_="category",
                    grid_index=6,
                    axislabel_opts=opts.LabelOpts(
                        is_show=True
                    ),
                ),
                yaxis_opts=opts.AxisOpts(
                    name="0AMV-指标",
                    name_location="middle",
                    name_gap=50,
                    name_textstyle_opts=opts.TextStyleOpts(
                        color="#ec0000",
                        font_size=16,
                        font_weight="bold"
                    )
                ),

                legend_opts=opts.LegendOpts(
                    is_show=True,
                    orient="vertical", pos_left="1%", pos_top="85%"

                ),
            )
        )
        amv_line = (Line()
                    .add_xaxis(xaxis_data=data['times'])
                    .add_yaxis(
            series_name="0AMV-C5",
            y_axis=data['0amv_c5'],
            symbol="diamond",
            symbol_size=6,
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(
                opacity=0.8, width=2, color="#fff000"),
            label_opts=opts.LabelOpts(is_show=False)
        )
            .add_yaxis(
            series_name="0AMV-C13",
            y_axis=data['0amv_c13'],
                symbol_size=6,
                symbol="rect",
                is_smooth=True,
                linestyle_opts=opts.LineStyleOpts(opacity=0.5),
                label_opts=opts.LabelOpts(is_show=False)
        )
            .add_yaxis(
            series_name="0AMV-C34",
            y_axis=data['0amv_c34'],
                symbol_size=6,
                symbol="pin",
                is_smooth=True,
                linestyle_opts=opts.LineStyleOpts(opacity=0.5),
                label_opts=opts.LabelOpts(is_show=False)
        )
            .add_yaxis(
            series_name="0AMV-Cinf",
            y_axis=data['0amv_cinf'],
                symbol_size=6,
                is_smooth=True,
                linestyle_opts=opts.LineStyleOpts(opacity=0.5),
                label_opts=opts.LabelOpts(is_show=False)
        )
            .set_global_opts(
                xaxis_opts=opts.AxisOpts(
                    type_="category", grid_index=1, axislabel_opts=opts.LabelOpts(is_show=False)),
                yaxis_opts=opts.AxisOpts(
                    grid_index=6,
                    split_number=3,
                    axisline_opts=opts.AxisLineOpts(is_on_zero=False),
                    axistick_opts=opts.AxisTickOpts(is_show=False),
                    splitline_opts=opts.SplitLineOpts(is_show=False),
                    axislabel_opts=opts.LabelOpts(is_show=True)
                ),
                legend_opts=opts.LegendOpts(
                    is_show=True, orient="vertical", pos_left="1%"),
        ))
        overlap_0amv_line = amvs_bar.overlap(amv_line)

        # 最后grid
        grid_chart = Grid(init_opts=opts.InitOpts(
            width="1900px", height="1900px", page_title=title_opt['title'],
            theme=ThemeType.LIGHT,))

        # 传参数至html中
        grid_chart.add_js_funcs("var barData={}".format(data['datas']))
        grid_chart.add_js_funcs("var amvbarData={}".format(data['0amv']))
        # k线图 index=0
        grid_chart.add(
            overlap_kline_ma,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                height="35%"),)
        # Volumn 柱状图 index =1
        grid_chart.add(
            overlap_vols_bar,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                pos_top="40%",
                height="15%")
        )
        # MACD DIFS and DEAs  index=2
        grid_chart.add(
            overlap_macd_bar_line,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                pos_top="55%",
                height="10%",
            ),
        )

        # DMI :ADXs DMps DMNs ADXRs
        grid_chart.add(
            dmi_line,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                pos_top="66%",
                height="5%",
            )
        )
        # CYE : CYEL CYES
        grid_chart.add(
            cye_line,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                pos_top="72%",
                height="5%",
            )
        )
        # CYE : CYEL CYES
        grid_chart.add(
            cyc_line,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                pos_top="78%",
                height="6%",
            )
        )
        grid_chart.add(
            overlap_0amv_line,
            grid_opts=opts.GridOpts(
                pos_left="10%",
                pos_right="1%",
                pos_top="85%",
                height="10%",
            )
        )

        grid_chart.render(outfile)

    def _draw_chart_line(self, data=None, outfile=None, title_opt=None, axis_opt=None):
        """
        画图-折线数据
        """
        line = (Line(init_opts=opts.InitOpts(
            width="1900px",
            height="900px",
            page_title=title_opt['title'],
            theme=ThemeType.LIGHT,

        ))
            .add_xaxis(data['times'])
            .add_yaxis(
                series_name=title_opt['title'],
                y_axis=data['datas'],

                is_smooth=False,
                itemstyle_opts=opts.ItemStyleOpts(
                    color="#ec0000",
                ),
                label_opts=opts.LabelOpts(is_show=False),
                linestyle_opts=opts.LineStyleOpts(width=3),




        )
            .set_global_opts(
                xaxis_opts=opts.AxisOpts(
                    is_scale=True,
                    name="日期",
                    name_location="center",
                    name_gap=30,
                    name_textstyle_opts=opts.TextStyleOpts(
                        color="#ec0000",
                        font_size=16,
                        font_weight="bold"
                    )
                ),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)
                ),
                name=axis_opt['yname'],
                name_location="middle",
                name_gap=100,
                name_textstyle_opts=opts.TextStyleOpts(
                    color="#ec0000",
                    font_size=16,
                    font_weight="bold"
                )
                ),
            datazoom_opts=[opts.DataZoomOpts(type_='inside')],
            title_opts=opts.TitleOpts(
                title=title_opt['title'],
                subtitle=title_opt['subtitle'],
                title_textstyle_opts=opts.TextStyleOpts(
                    font_size=25,
                    color="#ec0000"

                ),
                subtitle_textstyle_opts=opts.TextStyleOpts(
                    font_size=14
                ),
            ),
            toolbox_opts=opts.ToolboxOpts(
                is_show=True,
                # feature=opts.ToolBoxFeatureSaveAsImageOpts(
                #     type_='png',
                #     pixel_ratio=2)
                ),  # 工具箱

            tooltip_opts=opts.TooltipOpts(is_show=True),  # 提示框
        )

        )
        line.render(outfile)

    def _calculate_ma(self, day_count: int = 5, times=None, data=None):
        """
        param day_count int MA 天数参数
        param times -List 时间序列，列表
        parame data -list 计算MA的参数
        """
        result: List[Union[float, str]] = []

        for i in range(len(times)):
            if i < day_count:
                result.append("-")
                continue
            sum_total = 0.0
            for j in range(day_count):
                sum_total += float(data[i - j])
            result.append(abs(float("%.2f" % (sum_total / day_count))))
        return result

    def _get_dmi_indicator_data(self, pd_data, high=None, low=None, close=None):
        """
        返回dmi指标数据
        通过pandas_ta 获取ADX数据，包含，ADX_14 ,DMP_14,DMPN_14 ，需要添加 ADXR_14 指标数据
        """
        pd_data.ta.adx(high=high, low=low, close=close, append=True)
        adxr_value = []
        day_count = 6
        for i in pd_data.index:
            if (i-day_count) < 0:
                adxr_value.append(NaN)
            else:
                if pd_data['ADX_14'][i-day_count] == NaN:
                    adxr_value.append(NaN)
                else:
                    adxr_value.append(
                        (pd_data['ADX_14'][i]+pd_data['ADX_14'][i-day_count])/2)
        pd_data['ADXR_14'] = adxr_value

        return pd_data

    def _get_cye_indicator_data(self, pd_data, close=close):
        """
        CYE指标：
        返回两个 指标：CYEL，CYES
        """
        mal = pd_data.ta.sma(close=close, length=5)
        ma20 = pd_data.ta.sma(close=close, length=20)
        # print(ma20[1])
        mas = pd_data.ta.sma(close=ma20, length=5)
        cyel_value = []
        cyes_value = []
        for i in mal.index:
            if (i-1) < 0:
                cyel_value.append(NaN)
            else:
                if mal[i-1] == NaN:
                    cyel_value.append(NaN)
                else:
                    cyel_value.append(
                        ((mal[i]-mal[i-1]) / mal[i-1])*100)

        for i in mas.index:
            if (i-1) < 0:
                cyes_value.append(NaN)
            else:
                if mas[i-1] == NaN:
                    cyes_value.append(NaN)
                else:
                    cyes_value.append(
                        ((mas[i]-mas[i-1]) / mas[i-1])*100)
        pd_data['CYEL'] = cyel_value
        pd_data['CYES'] = cyes_value

        return pd_data

    def _get_cyc_indicator_data(self, pd_data, length=5,):
        """
        CYC 5,13,34  cyc_inf
        """
        ema_amount = pd_data.ta.ema(close="amount_0", length=length)
        ema_vols = pd_data.ta.ema(close="vol_0", length=length)
        cyc_ = []
        for i in ema_amount.index:
            if ema_amount[i] == NaN:
                cyc_.append(NaN)
            else:
                cyc_.append(ema_amount[i]/ema_vols[i])

        pd_data['cyc_{0}'.format(length)] = cyc_
        return pd_data

    def __cyc_inf(self, pd_data):
        """
        CYC无穷的 获取，主要是DMA算法
        cyc_inf=DMA(AMOUNT/(100*VOL),VOL/FINANCE(7))    FINANCE(7) 流通股本
        """
        cyc_inf = []
        pd_data['X_'] = pd_data.apply(
            lambda x: x['amount_0']/x['vol_0'], axis=1)
        pd_data['A_'] = pd_data.apply(lambda x: x['vol_0']/x['tq_0'], axis=1)

        pd_ = pd_data[['X_', 'A_']]

        # print(pd_.head(5))

        for i in pd_data.index:
            X = pd_['X_'].head(i+1).values.tolist()
            A = pd_['A_'].head(i+1).values.tolist()
            inf_ = reduce(lambda x, y: (
                1 - y[1]) * x + y[1] * y[0], zip(X, A), X[0])
            cyc_inf.append(inf_)

        pd_data.drop('X_', axis=1, inplace=True)
        pd_data.drop('A_', axis=1, inplace=True)
        pd_data['cyc_inf'] = cyc_inf
        return pd_data

    def _get_oamv_indicator_data(self, pd_data):
        """
        0AMV 指南针指标，活筹指数,返回 0amv,c5,c13,c34,cinf 
        """
        # print(pd_data.head(5))
        pd_data.ta.sma(
            close='amount_0', length=10, offset=1, prefix='0amv', append=True)
        pd_data.ta.sma(
            close='amount_0', length=3, offset=1, prefix='0amv_c5', append=True)
        pd_data.ta.sma(
            close='amount_0', length=5, offset=1, prefix='0amv_c13', append=True)
        pd_data.ta.sma(
            close='amount_0', length=8, offset=1, prefix='0amv_c34', append=True)

        pd_data['A_c5'] = pd_data.apply(
            lambda x: x['vol_0']/x['tq_0']/0.02, axis=1)
        pd_data['A_c13'] = pd_data.apply(
            lambda x: x['vol_0']/x['tq_0']/0.1, axis=1)
        pd_data['A_c34'] = pd_data.apply(
            lambda x: x['vol_0']/x['tq_0']/0.18, axis=1)
        pd_data['A_cinf'] = pd_data.apply(
            lambda x: x['vol_0']/x['tq_0']/1.1, axis=1)
        pd_ = pd_data[['0amv_SMA_10', '0amv_c5_SMA_3', '0amv_c13_SMA_5',
                       '0amv_c34_SMA_8', 'A_c5', 'A_c13', 'A_c34', 'A_cinf']]
        # print(pd_.head(50))
        pd_.fillna(0, inplace=True)
        c5 = []
        c13 = []
        c34 = []
        cinf = []
        for i in pd_.index:
            X = pd_['0amv_c5_SMA_3'].head(i+1).values.tolist()
            A = pd_['A_c5'].head(i+1).values.tolist()
            dma = reduce(lambda x, y: (1 - y[1])
                         * x + y[1] * y[0], zip(X, A), X[0])
            c5.append(dma)
        for i in pd_.index:
            X = pd_['0amv_c13_SMA_5'].head(i+1).values.tolist()
            A = pd_['A_c13'].head(i+1).values.tolist()
            dma = reduce(lambda x, y: (1 - y[1])
                         * x + y[1] * y[0], zip(X, A), X[0])
            c13.append(dma)
        for i in pd_.index:
            X = pd_['0amv_c34_SMA_8'].head(i+1).values.tolist()
            A = pd_['A_c34'].head(i+1).values.tolist()
            dma = reduce(lambda x, y: (1 - y[1])
                         * x + y[1] * y[0], zip(X, A), X[0])
            c34.append(dma)

        for i in pd_.index:
            X = pd_['0amv_SMA_10'].head(i+1).values.tolist()
            A = pd_['A_cinf'].head(i+1).values.tolist()
            dma = reduce(lambda x, y: (1 - y[1])
                         * x + y[1] * y[0], zip(X, A), X[0])
            cinf.append(dma)

        pd_data.rename(columns={"0amv_SMA_10": '0amv'}, inplace=True)
        pd_data['0amv_c5'] = c5
        pd_data['0amv_c13'] = c13
        pd_data['0amv_c34'] = c34
        pd_data['0amv_cinf'] = cinf

        pd_data.drop('0amv_c5_SMA_3', axis=1, inplace=True)
        pd_data.drop('0amv_c13_SMA_5', axis=1, inplace=True)
        pd_data.drop('0amv_c34_SMA_8', axis=1, inplace=True)

        pd_data.drop('A_c5', axis=1, inplace=True)
        pd_data.drop('A_c13', axis=1, inplace=True)
        pd_data.drop('A_c34', axis=1, inplace=True)
        pd_data.drop('A_cinf', axis=1, inplace=True)

        return pd_data

    def _get_0mav_intime__indicator_data(self, pd_data):
        """
        0amv 实时指数 open, close, hight ,low ,ma5, ma 10
        CYF13 =100-100/(1+EMA(HSL,13))

        适用0A指数 
        """
        pd_data['hsl'] = pd_data.apply(lambda x: x['vol_0']/x['tq_0'], axis=1)
        ema_hsl_13 = pd_data.ta.ema(close='hsl', length=13, prefix='hsl')
        CYF13 = []
        for i in ema_hsl_13.index:
            if ema_hsl_13[i] == NaN:
                CYF13.append(NaN)
            else:
                CYF13.append(100-100/(1+ema_hsl_13[i]))

        pd_data['cyf_13'] = CYF13
        # open
        pd_data['0amvo'] = pd_data.apply(
            lambda x: x['cyf_13']*x['open_0A'], axis=1)
        # high
        pd_data['0amvh'] = pd_data.apply(
            lambda x: x['cyf_13']*x['high_0A'], axis=1)
        # low
        pd_data['0amvl'] = pd_data.apply(
            lambda x: x['cyf_13']*x['low_0A'], axis=1)
        # close
        pd_data['0amvc'] = pd_data.apply(
            lambda x: x['cyf_13']*x['close_0A'], axis=1)

        pd_data.drop('hsl', axis=1, inplace=True)
        pd_data.drop('cyf_13', axis=1, inplace=True)

        pd_data.ta.sma(close='0amvc', length=5, prefix='0amvcma5', append=True)
        pd_data.ta.sma(close='0amvc', length=10,
                       prefix='0amvcma10', append=True)

        return pd_data

    def _test(self):
        bar = Bar()
        bar.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
        bar.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
        # render 会生成本地 HTML 文件，默认会在当前目录生成 render.html 文件
        # 也可以传入路径参数，如 bar.render("mycharts.html")
        outfile = self.outdir+"test.html"
        bar.render(outfile)
